home *** CD-ROM | disk | FTP | other *** search
- #include "cd2pcm.h"
- #include "extern.h"
-
-
- /* bin を時間 bcd に変換する。*/
- int bin2time( int bin )
- {
- int i;
- int ans = 0;
-
- static int bin2time_tbl[2] = { 60*75, 75 };
-
- for( i = 0 ; i < 2 ; i++ )
- {
- ans = ans << 8;
- ans += bin / bin2time_tbl[i];
- bin = bin % bin2time_tbl[i];
- }
- ans = ans << 8;
- ans += bin;
-
- return( ans );
- }
-
- /* 時間 bcd を bin に変換する。*/
- int time2bin( int time )
- {
- /* 00:mm:ss:xx 何分何秒何1/75秒 */
- return( ( (time >> 16) & 0xff ) * 60*75 +
- ( (time >> 8) & 0xff ) * 75 +
- ( time & 0xff ) );
- }
-
- /* 時間を秒に変換する */
- int adr2time( int address )
- {
- int ans;
-
- ans = ( ( address >> 16 ) & 0xff ) * 60 * 75; /* 分をフレームに変える */
- ans += ( ( address >> 8 ) & 0xff ) * 75; /* 秒をフレームに買える */
- ans -= 2*75; /* 2秒補正する。 */
- ans += ( address & 0xff ); /* フレームをそのまま加える */
-
- return( ans );
- }
-
- /* 演奏時間を表示する。*/
- void cd_play_list( void )
- {
- int leadout_address,min,max,i,start,end,cnt;
- char *s;
- if ( RedTOC( &leadout_address, &min, &max ) != 0 ){
- printf( "Leadout Track Address or ReadTOC Command error "
- "のため演奏時間はわかりませんでした。\n");
- return;
- }
- for( i = min ; i <= max ; i++ ){
- if ( Music_inf( i, &start ) != 0 ){
- printf( "Start Track Address or ReadTOC Command error "
- "のため演奏時間はわかりませんでした。\n");
- return;
- }
- if ( i == min ){
- if ( CDC_ID==SCSI_ID )
- s=(void*)CDCTNAME(-1);
- else s=0;
- if ( s!=0 ) printf("\n[%s]",NameCenter(s) );
-
- end = bin2time( time2bin(leadout_address) -
- time2bin(start) );
-
- printf("\n全ての曲の演奏時間は%2d分%02d秒%02dです。\n",
- (end >> 16) & 0xff, (end >> 8) & 0xff,
- end & 0xff );
- printf(" 曲番号 演奏時間 開始時間");
- printf(" 終了時間\n");
- }
-
- if ( i == max ){
- end = bin2time( time2bin(leadout_address) -1);
- } else {
- if ( Music_inf( i+1, &end) != 0 ){
- printf( "Start Track Address or "
- "ReadTOC Command error "
- "のため演奏時間はわかりませんでした。\n");
- return;
- } else
- end = bin2time( time2bin( end ) -1);
- }
- cnt = bin2time( time2bin(end) - time2bin(start) +1 );
-
- printf("%3d 曲目 %2d分%02d秒%02d ",i,
- (cnt >> 16) & 0xff, (cnt >> 8) & 0xff,
- cnt & 0xff );
-
- printf("%2d分%02d秒%02d ~ %2d分%02d秒%02d",
- (start >> 16) & 0xff, (start >> 8 ) & 0xff,
- start & 0xff,
- ( end >> 16) & 0xff, ( end >> 8 ) & 0xff,
- end & 0xff );
-
- if ( CDC_ID==SCSI_ID )
- s=(void*)CDCTNAME(i);
- else s=0;
- if ( s!=0 ) printf(" %s",NameCenter(s) );
-
- printf("\n");
- }
- return;
- }
-
- /* 現在の状態と演奏曲数を表示する。*/
- void cd_play_inf( void )
- {
- int dumy,min,max;
- PLYINF plyinf;
- char *s;
-
- if ( RedTOC( &dumy, &min, &max ) == 0 )
- {
- if ( CDC_ID==SCSI_ID )
- s=(void*)CDCTNAME(-1);
- else s=0;
- if ( s!=0 ) printf("[%s]\n",NameCenter(s) );
-
- printf("曲番号は、%d ~ %d まで有効です。\n", min, max );
-
- if ( ChkPly( &plyinf ) == 0 )
- {
- if ( ( plyinf.fg & 0x1f ) == 0x12 )
- {
- /* 中断している。 */
- printf("%d 曲目の %2d分%02d秒%02dで中断しています。",
- plyinf.track_no,
- ( plyinf.time / 0x10000 ) & 0xff ,
- ( plyinf.time / 0x100 ) & 0xff ,
- plyinf.time & 0xff );
-
- printf("現在の演奏時間は、%2d分%02d秒%02dです。\n",
- ( plyinf.address / 0x10000 ) & 0xff ,
- ( plyinf.address / 0x100 ) & 0xff ,
- plyinf.address & 0xff );
- }
- else if ( ( plyinf.fg & 0x1f ) == 0x11 )
- {
- /* 演奏している */
- printf("%d 曲目の %2d分%02d秒%02dを演奏中です。",
- plyinf.track_no,
- ( plyinf.time / 0x10000 ) & 0xff ,
- ( plyinf.time / 0x100 ) & 0xff ,
- plyinf.time & 0xff );
-
- printf("現在の演奏時間は、%2d分%02d秒%02dです。\n",
- ( plyinf.address / 0x10000 ) & 0xff ,
- ( plyinf.address / 0x100 ) & 0xff ,
- plyinf.address & 0xff );
- }
- else
- {
- /* 演奏していない。*/
- }
- }
- else
- printf("Read Drive Status Command error \n");
- }
- else
- {
- printf( "Leadout Track Address or ReadTOC Command error "
- "のため演奏で来ませんでした。\n");
- }
- }
-
- /* 演奏を中断する。*/
- void cd_play_pause( void )
- {
- if ( StpDsk() == 0 ){
- printf("演奏を中断します。\n");
- } else
- printf("Pause/Resume Command error \n");
- }
-
- /* 演奏時間を指定して演奏する。*/
- void cd_play2( int num, int start, int end )
- {
- int leadout_address,adr;
- int min,max;
-
- if ( RedTOC( &leadout_address, &min, &max ) == 0 )
- {
- if ( num != 0 )
- {
- /* 演奏時間は、オフセット指定 */
- if ( num > max )
- {
- printf("曲番号の指定が大きすぎます。\n");
- return;
- }
- if ( Music_inf( num, &adr ) == 0 )
- {
- start = start + time2bin(adr);
- if ( end != -1 )
- end = end + time2bin(adr);
- }
- else
- {
- printf( "Start Track Address or ReadTOC Command error "
- "のため演奏時間はわかりませんでした。\n");
- return;
- }
- }
-
- if ( end == -1 )
- /* 最後まで演奏する */
- end = time2bin(leadout_address) - 1;
-
- if ( time2bin(leadout_address) -1 < start )
- {
- printf("演奏開始時間の設定が大きすぎます。\n");
- return;
- }
- if ( time2bin(leadout_address) -1 < end )
- {
- printf("演奏終了時間の設定が大きすぎます。\n");
- return;
- }
-
-
- /* 演奏開始 */
- if ( PlyDsk( bin2time(start), bin2time(end) ) != 0 )
- printf("Play Audio Begin ・ Play Audio Block Count Command error のため演奏できませんでした。\n");
- }
- else
- {
- printf( "Leadout Track Address or ReadTOC Command error "
- "のため演奏できませんでした。\n");
- }
- }
-
- /* 一曲だけ演奏する。*/
- void cd_play( int start, int end )
- {
- int start_address,end_address,leadout_address;
- int min,max;
-
- if ( RedTOC( &leadout_address, &min, &max ) == 0 )
- {
- if ( end == -1 )
- {
- /* 最後まで演奏する */
- end = max;
- }
-
- if ( ( start >= min && start <= max ) && ( end >= min && end <= max ) )
- {
- if ( Music_inf( start, &start_address ) == 0 )
- {
- if ( end == max )
- end_address = leadout_address;
- else
- {
- if (Music_inf( end+1,&end_address ) != 0 )
- {
- printf( "Start Track Address or "
- "ReadTOC Command error "
- "のため演奏できませんでした。\n");
- return;
- }
- }
-
- /* 演奏開始 */
- end_address = bin2time( time2bin(end_address ) -1 );
- if ( PlyDsk( start_address, end_address ) == 0 )
- ;
- else
- {
- printf( "Play Audio Begin ・ Play Audio Block "
- "Count Command error のため演奏できませんでした。"
- "\n");
- }
- }
- else
- {
- printf( "Start Track Address or ReadTOC "
- "Command error のため演奏できませんでした。\n");
- }
- }
- else
- {
- printf( "指定された曲番号は、存在しません。\n"
- "曲番号は、%d ~ %d まで有効です。\n", min, max );
- }
- }
- else
- {
- printf( "Leadout Track Address or ReadTOC Command error "
- "のため演奏できませんでした。\n");
- }
- }
-
- /* 全曲を演奏する。*/
- void cd_play_all( void )
- {
- int start_address,leadout_address,min,max;
-
- if ( RedTOC( &leadout_address, &min, &max ) == 0 )
- {
- if ( Music_inf( min , &start_address ) == 0 )
- {
- leadout_address = bin2time( time2bin(leadout_address ) -1 );
- if ( PlyDsk(start_address,leadout_address) == 0 ) /* 演奏開始 */
- ;
- else
- {
- printf( "Play Audio Begin or Play Audio Block Count"
- " Command error のため演奏できませんでした。\n");
- }
- }
- else
- {
- printf( "Start Track Address or ReadTOC "
- "Command error のため演奏できませんでした。\n");
- }
- }
- else
- {
- printf( "Leadout Track Address or ReadTOC Command error "
- "のため演奏できませんでした。\n");
- }
- }
-
-
- /* 演奏を再開させる。*/
- void cd_play_resume( void )
- {
- PLYINF plyinf;
-
- if ( ChkPly( &plyinf ) == 0 )
- {
- if ( ( plyinf.fg & 0x1f ) == 0x12 )
- {
- if ( Resume() == 0 )
- printf("演奏を再開します。\n");
- else
- printf("演奏再開に失敗しました。\n");
- }
- else if ( ( plyinf.fg & 0x1f ) == 0x11 )
- {
- printf("現在演奏は、中断していません。\n");
- cd2pcm_help();
- }
- else
- {
- printf("現在演奏していません。\n");
- }
- }
- else
- {
- printf("Read Drive Status Command error \n");
- }
- }